/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.onlylemi.mapview.slice;

import com.onlylemi.mapview.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        Text tvTitle = (Text) findComponentById(ResourceTable.Id_tv_title);
        tvTitle.setText("MapView");

        findComponentById(ResourceTable.Id_bt_1).setClickedListener(this);
        findComponentById(ResourceTable.Id_bt_2).setClickedListener(this);
        findComponentById(ResourceTable.Id_bt_3).setClickedListener(this);
        findComponentById(ResourceTable.Id_bt_4).setClickedListener(this);
        findComponentById(ResourceTable.Id_bt_5).setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_bt_1:
                Intent intent1 = new Intent();
                Operation operation1 = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(MapLayerTestAbility.class.getName())
                        .build();
                intent1.setOperation(operation1);
                startAbility(intent1);
                break;
            case ResourceTable.Id_bt_2:
                Intent intent2 = new Intent();
                Operation operation2 = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(BitmapLayerTestAbility.class.getName())
                        .build();
                intent2.setOperation(operation2);
                startAbility(intent2);
                break;
            case ResourceTable.Id_bt_3:
                Intent intent3 = new Intent();
                Operation operation3 = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(LocationLayerTestAbility.class.getName())
                        .build();
                intent3.setOperation(operation3);
                startAbility(intent3);
                break;
            case ResourceTable.Id_bt_4:
                Intent intent4 = new Intent();
                Operation operation4 = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(MarkLayerTestAbility.class.getName())
                        .build();
                intent4.setOperation(operation4);
                startAbility(intent4);
                break;
            case ResourceTable.Id_bt_5:
                Intent intent5 = new Intent();
                Operation operation5 = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(RouteLayerTestAbility.class.getName())
                        .build();
                intent5.setOperation(operation5);
                startAbility(intent5);
                break;
            default:
                break;
        }
    }
}
